//
//  TableShowWKWebCellModel.swift
//  CooperSwift
//
//  Created by 计海峰 on 2022/1/17.
//

import Foundation
import UIKit
import WebKit

public class TableShowWKWebCellModel : NSObject, PublicTableCellConfigProtocol, BindKeyProtocol {
   
    /// 默认
    public var model: Any?
    
    /// 配置
    public var isUserInteractionEnabled: Bool = false
    
    //  MARK: - 基础实现
    required public init(_ model: Any?) {
        self.model = model
    }
    
    public func cellCls() -> UITableViewCell.Type {
        return TableShowWKWebCell.self
    }
    
    
    public typealias TargetType = WKWebView
    
    // MARK: - 回调
    /// 单次
    @MainActor public func once(_ webview: WKWebView, cell: UITableViewCell) {
        webview.isUserInteractionEnabled = self.isUserInteractionEnabled
        if let webControl = self.model as? ViewControlProtocol {
            webview.snp.updateConstraints { make in
                make.edges.equalToSuperview().inset(webControl.padding)
            }
            webControl.loadAll(webview, judgeType: true)
        }
    }
    
    /// 多次
    public func every(_ webview: WKWebView, cell: UITableViewCell) {
        webview.reload()
    }
    
}
